﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Net.Http;
using System.Threading.Tasks;
using Lhn.Ds.Core.Controll;

namespace Lhn.Ds.Core.Service
{
    [Export]
    public class CardService : BaseService
    {
        public async Task<Card> GetCard(string code)
        {
            return await Client.Post<Card>("/icCard/getByCode",
                new FormUrlEncodedContent(new[] {new KeyValuePair<string, string>("code", code)}));
        }

        public async Task DeleteCard(long id)
        {
            await Client.Post<object>("/icCard/delete",
                new FormUrlEncodedContent(new[] {new KeyValuePair<string, string>("id", id.ToString()) }));
        }
        public async Task SaveCard(Card card)
        {
            await Client.Post<object, Card>("/icCard/save", card);
        }

        public class Card
        {
            private string _phoneNum;
            private string _userCodeId;
            private string _cardNumber;
            public long Id { get; set; }
            public string Code { get; set; }
            public string CardNumber
            {
                get => _cardNumber??"";
                set => _cardNumber = value;
            }

            public string UserCodeId
            {
                get => _userCodeId??"";
                set => _userCodeId = value;
            }

            public int Balance { get; set; }
            public int TotalConsumption { get; set; }
            public CardState State { get; set; }
            public DateTime SynchronisedTime { get; set; }
            public CarTypeEnum CardType { get; set; }

            public string PhoneNum
            {
                get => _phoneNum??"";
                set => _phoneNum = value;
            }
        }
    }
}